package cn.com.anysdk.redis.demo.controller;

import cn.com.anysdk.redis.starter.RedisConfigPropertiesSpringBoot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Hello World控制器
 * 测试应用启动和配置读取
 */
@RestController
@RequestMapping("/api")
public class HelloController {

    @Autowired
    private RedisConfigPropertiesSpringBoot redisProperties;

    @GetMapping("/hello")
    public Map<String, Object> hello() {
        Map<String, Object> result = new HashMap<>();
        result.put("message", "Hello AnySDK Redis!");
        result.put("environment", redisProperties.getEnvironment());
        result.put("localHost", redisProperties.getLocal().getHost());
        result.put("localPort", redisProperties.getLocal().getPort());
        return result;
    }

    @GetMapping("/config")
    public Map<String, Object> getConfig() {
        Map<String, Object> result = new HashMap<>();
        result.put("environment", redisProperties.getEnvironment());

        Map<String, Object> localConfig = new HashMap<>();
        localConfig.put("host", redisProperties.getLocal().getHost());
        localConfig.put("port", redisProperties.getLocal().getPort());
        localConfig.put("database", redisProperties.getLocal().getDatabase());
        result.put("local", localConfig);

        return result;
    }
}